from flask import request

from . import app_verify_code

from .send_sms import SendSms

@app_verify_code.route('/send_sms',methods=['POST'])

def send_code():

    info=request.form

    phone=info.get('phone')

    with SendSms(phone) as s:

        result=s.can_i_sms()
        
        if not result:

            return {
                "status": -1,
                "errorCode": 1,
                "errorMsg": '你刚刚已经发送过一条短信',
                "resultBody": None,
                }

        info=s.verification_code()

        if info['status']==1:

            res=s.send_sms()
        
            return res
        else:

            return info

    
